package StudyCode.summary.mycollection;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CheckWhetherTheGivenIteratorContainsTheGivenElement {
	public static void main(String[] argv) {
		Iterator iterator = java.util.Arrays.asList("asdf", "www.tah1986.com")
				.iterator();
		Object element = "www.tah1986.com";
		System.out.println(contains(iterator, element));
	}


	public static boolean contains(Iterator<?> iterator, Object element) {
		if (iterator != null) {
			while (iterator.hasNext()) {
				Object candidate = iterator.next();
				if (candidate.equals(element)) {
					return true;
				}
			}
		}
		return false;
	}


	public static boolean contains(Enumeration<?> enumeration,
	                               Object element) {
		if (enumeration != null) {
			while (enumeration.hasMoreElements()) {
				Object candidate = enumeration.nextElement();
				if (candidate.equals(element)) {
					return true;
				}
			}
		}
		return false;
	}
}
